#include "gtest/gtest.h"
#include "hashmap.hpp"

using namespace yfwz100::fundamental;

class HashMapTest : public ::testing::Test
{
protected:
  HashMapTest() : smallMap(2, 1)
  {
    // init the ordinary map.
    map[1] = 1;
    map[2] = 3;
    map[17] = 2;
  }

  HashMap<int, int> map;
  HashMap<int, int> emptyMap;
  HashMap<int, int> smallMap;
};

TEST_F(HashMapTest, is_empty)
{
  ASSERT_TRUE(emptyMap.is_empty());
}

TEST_F(HashMapTest, check_conflict)
{
  ASSERT_EQ(map[1], 1);
  ASSERT_EQ(map[2], 3);
  ASSERT_EQ(map[17], 2);
}

TEST_F(HashMapTest, size)
{
  ASSERT_EQ(map.size(), 3);
  ASSERT_EQ(emptyMap.size(), 0);
}

TEST_F(HashMapTest, resize_by_insert)
{
  smallMap.insert(1, 2);
  smallMap.insert(2, 3);
  smallMap.insert(3, 4);
  ASSERT_EQ(smallMap.capacity(), 4);
  ASSERT_EQ(smallMap[1], 2);
  ASSERT_EQ(smallMap[2], 3);
  ASSERT_EQ(smallMap[3], 4);
}

TEST_F(HashMapTest, resize_by_ref)
{
  smallMap[1] = 2;
  smallMap[2] = 3;
  smallMap[3] = 4;
  ASSERT_EQ(smallMap.capacity(), 4);
  ASSERT_EQ(smallMap[1], 2);
  ASSERT_EQ(smallMap[2], 3);
  ASSERT_EQ(smallMap[3], 4);
}